import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './vuex/store'  //当需要更新数据，对状态进行管理时，就要引入vuex里的store来进行对状态的处理
import './registerServiceWorker'

import apis from '@/apis/api'
//封装后引入
	import axios from '@/utils/axios'
	import 'reset-css'
//导入element-ui
	import ElementUI from 'element-ui'
	import 'element-ui/lib/theme-chalk/index.css'
	Vue.use(ElementUI);
//引入font-awsome
	import '@/assets/css/font-awesome.css'
	//引入mixin
	import '@/components/mixins/mixins'
	import '@/assets/css/table.css'

	Vue.config.productionTip = false
//console.log(process.env.VUE_APP_SECRET);
//console.log(process.env.VUE_APP_ROOTAPI);
//注册全局的基础路径
	Vue.prototype.$baseURL=process.env.VUE_APP_ROOTAPI
//导入api接口对象，@表示在src目录下
	Vue.prototype.$apis=apis
//将axios注册为全局属性，可通过this.$http发起请求
	Vue.prototype.$http=axios

//配置路由守卫实现登录跳转
	router.beforeEach((to,from,next)=>{
			//先判断是否去登录,清除登录记录
			if(to.path==="/signin"){
				localStorage.removeItem('token');
				next();
			}
			else{
				//判断是否已经登录，获取令牌
				if(localStorage.getItem('token')){
					next();
				}
				else{
					//如果没有登录，则去登陆界面，并传值在登录后跳转到本来要去的页面
					next({path:'/signin',query:{redirect:to.path}});
				}
			}
	})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
